#!/usr/bin/env python
# -*- coding:utf-8 -*-
# @Time : 2022-2-28 11:27
# @Author : huabao.tan
# @File : send_email.py
# @Software: PyCharm

import smtplib
from email.mime.text import MIMEText
from email.header import Header
from tool.allFunction.Function import *

class Mail:
    def __init__(self):
        self.mail_host = "smtp.qq.com"
        self.mail_pass = "horxhhovpbpmbfge" #邮箱的验证码
        self.sender = "1045570877@qq.com"
        self.receivers = ["2404173292@qq.com", "thbrjcs@163.com"]
        self.create = create_msg()

    def send(self):
        contnet = self.create
        message = MIMEText(contnet, 'plain', 'utf-8')
        message['From'] = Header('超级大帅比', "utf-8")
        message["To"] = Header("小老弟你不行啊！", "utf-8")
        subject = "SEND_EMAIL"
        message["Subject"] = Header(subject, "utf-8")
        try:
            smtpObj = smtplib.SMTP_SSL(self.mail_host, 465)
            smtpObj.login(self.sender, self.mail_pass)
            smtpObj.sendmail(self.sender, self.receivers, message.as_string())
            smtpObj.quit()
            print("邮件发送成功")
        except smtplib.SMTPException as e:
            print(e)
            print("邮件发送成功")
